﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NIKE_Project.DAL;

namespace NIKE_Project.BLL
{
    public class SalesReturnServer
    {
        //引用DBHelper类
        DBHelper db = new DBHelper();

        public DataSet Sales(string receiptsCode)
        {
            DataSet ds;
            //获取根据“销售记录表”查询交易金额
            string Amount = string.Format("select Amount from Sales where ReceiptsCode='{0}'", receiptsCode);
            ds = db.getDataSet(Amount);
            return ds;
        }

        public DataSet Goods(string receiptsCode)
        {
            //根据 “商品名称表”“销售记录表”“销售明细表”“员工信息表”查询退货界面商品信息
            string Sql = string.Format(@"select Se.SalesID,Sd.SDID,G.BarCode,G.GoodsName,Sd.AloneAmount,Sd.Quantity,Sn.SalesmanName,Se.SalesDate from Goods G,Salesan Sn,Sales Se,SalesDetail Sd 
                                       where  G.GoodsID=Sd.GoodsID and Sn.SalesmanID=Se.SalesmanID and Se.SalesID=Sd.SalesID and Se.ReceiptsCode='{0}'", receiptsCode);
            DataSet ds = db.getDataSet(Sql);
            return ds;
        }

        public DataSet SalesList()
        {
            DataSet ds;
            //获取根据“销售记录表”查询交易金额
            string Sql = @"select se.ReceiptsCode,se.Amount,se.SalesDate,Sn.SalesmanName,Ca.SalesmanName as CashierName from Sales se 
            join Salesan Sn on Sn.SalesmanID = se.SalesmanID 
            join Salesan Ca on Ca.SalesmanID = se.CashierID  ";
            ds = db.getDataSet(Sql);
            return ds;
        }
        public DataSet SalesList(string aloneAmount, string salesManName)
        {
            DataSet ds;
            //获取根据“销售记录表”查询交易金额
            string Sql = string.Format(@"select se.ReceiptsCode,se.Amount,se.SalesDate,Sn.SalesmanName,Ca.SalesmanName as CashierName from Sales se 
            join Salesan Sn on Sn.SalesmanID = se.SalesmanID 
            join Salesan Ca on Ca.SalesmanID = se.CashierID 
            where se.Amount like '%{0}%' and Sn.SalesmanName like '%{1}%'", aloneAmount, salesManName);
            ds = db.getDataSet(Sql);
            return ds;
        }

    }
}
